const { createProxyMiddleware } = require('http-proxy-middleware')
const Bundler = require('parcel-bundler')
const express = require('express')

const bundler = new Bundler('src/index.html', {
    cache: true
})

var args = process.argv.splice(2)
console.log("env", args);
var env = args[0];
var apiUrl = env == "TEST" ?
    "http://xx.xx.xx.66:6606" : 'http://localhost:8899'
console.log("apiUrl", apiUrl)

var port = process.env.PORT;
console.info(`port: ${port}`);

const app = express()
app.use('/api', createProxyMiddleware({ target: apiUrl }))
app.use(bundler.middleware())
app.listen(Number(port || 1234))